package com.hsteach.enums;

import com.hsteach.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum VisitOrderByEnum {

    VISIT_TIMES(1, "按家访次数正序排序"),
    VISIT_TIMES_DESC(2, "按家访次数倒序排序"),
    SPECIAL_STUDENT(3, "特殊学生类型优先"),
    ;

    private Integer code;
    private String name;

    public static VisitOrderByEnum getByCode(Integer code) {
        VisitOrderByEnum visitOrderByEnum = Arrays.stream(VisitOrderByEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        if (visitOrderByEnum == null) {
            throw new ServiceException("不存在的排序方式");
        }
        return visitOrderByEnum;
    }
}
